﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZSZ.Core.Entities;

namespace ZSZ.EntityFramework.ModelConfig
{
    class RolePermissionConfig: EntityTypeConfiguration<RolePermissionEntity>
    {
        public override void Map(EntityTypeBuilder<RolePermissionEntity> builder)
        {
            builder.ToTable("T_RolePermission");
            builder.HasOne(e => e.Role).WithMany(t => t.RolePermission).HasForeignKey(u => u.RoleId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            builder.HasOne(e => e.Permission).WithMany(t => t.RolePermission).HasForeignKey(u => u.PermissionId)
                .OnDelete(DeleteBehavior.ClientSetNull);
        }
    }
}